package com.z_talk.server.localization;

import com.z_talk.core.util.FileUtil;
import com.z_talk.server.config.PropertiesUtil;

import java.io.*;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

public class NoticeLocalzation {


    public static String loadNotice()  {
        try {
            String filePath = PropertiesUtil.configProp.getProperty("filePath");
            String fileName = PropertiesUtil.configProp.getProperty("noticeFile");
            File file =  FileUtil.createFile(filePath+fileName);
            Path fpath= Paths.get(file.getPath());
            String notice = new String(Files.readAllBytes(fpath));
            return notice;
        }catch (EOFException e) {
            return new String();
        }catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

    public static boolean saveNotice(String notice){
        try {
            String filePath = PropertiesUtil.configProp.getProperty("filePath");
            String fileName = PropertiesUtil.configProp.getProperty("noticeFile");
            File file =   FileUtil.createFile(filePath+fileName);
            Files.write(Paths.get(file.getPath()),notice.getBytes());
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }


}
